package com.mdg.bike;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class PathOverlay extends Overlay {
	
	private List<GeoPoint> points;
	
	public PathOverlay(Context _con) {
		points = new LinkedList<GeoPoint>();
	}

	public void draw(Canvas canvas, MapView mapv, boolean shadow){
		super.draw(canvas, mapv, shadow);
		
		Paint   mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(Color.GREEN);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(2);
        /* 
        GeoPoint gP1 = new GeoPoint(44092196, -70211068);
        GeoPoint gP2 = new GeoPoint(44791518, -68777202);
        GeoPoint gP3 = new GeoPoint(45653421, -68707179);
        GeoPoint gP4 = new GeoPoint(46679415, -70450929);
        GeoPoint gP5 = new GeoPoint(37322998, -122032182);
        
        Point p1 = new Point();
        Point p2 = new Point();
        Point p3 = new Point();
        Point p4 = new Point();
        Point p5 = new Point();
*/
        Path path = new Path();
        
        Projection projection = mapv.getProjection();
        
        Iterator<GeoPoint> it = points.iterator();
        Point p = null;
        while(it.hasNext()){
        	Point nextPoint = new Point();
        	projection.toPixels(it.next(), nextPoint);
        	
        	if (p != null) {
        		path.moveTo(nextPoint.x, nextPoint.y);
        		path.lineTo(p.x, p.y);
        	}
        	
        	p = nextPoint;
        }
        /*
        projection.toPixels(gP1, p1);
        projection.toPixels(gP2, p2);
        projection.toPixels(gP3, p3);
        projection.toPixels(gP4, p4);
        projection.toPixels(gP5, p5);
        
        path.moveTo(p2.x, p2.y);
        path.lineTo(p1.x,p1.y);

        path.moveTo(p2.x, p2.y);
        path.lineTo(p3.x, p3.y);
        
        path.moveTo(p3.x, p3.y);
        path.lineTo(p4.x, p4.y);
        
        path.moveTo(p4.x, p4.y);
        path.lineTo(p5.x, p5.y);
        */
        canvas.drawPath(path, mPaint);
    }
	
	public void addPathPoint(GeoPoint p){
		points.add(p);
	}
}
